package com.bbu.javaexam.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bbu.javaexam.domain.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName Teacher.java
 * @Description TODO
 */
@Mapper
public interface TeacherMapper extends BaseMapper<Teacher> {
    /**
     * @throws
     * @title 通过分页查询所有老师
     * @description
     * @author Alex
     */
    @Select("select * from teacher")
    IPage<Teacher> findAll(Page page);

    /**
     * @throws
     * @title 不分页查找所有老师
     * @description
     * @author Alex
     */
    @Select("select * from teacher")
    public List<Teacher> findAll();

    /**
     * @throws
     * @title 通过ID查找指定老师
     * @description
     * @author Alex
     */
    @Select("select * from teacher where teacherId = #{teacherId}")
    public Teacher findById(Integer teacherId);

    /**
     * @throws
     * @title 通过指定ID删除老师
     * @description
     * @author Alex
     */
    @Delete("delete from teacher where teacherId = #{teacherId}")
    public int deleteById(Integer teacherId);

    /**
     * @throws
     * @title 传递一个对象来更新老师信息
     * @description
     * @author Alex
     */
    @Update("update teacher set teacherName = #{teacherName},sex = #{sex}," +
            "tel = #{tel}, email = #{email},pwd = #{pwd},cardId = #{cardId}," +
            "role = #{role},institute = #{institute},type = #{type} where teacherId = #{teacherId}")
    public int update(Teacher teacher);

    /**
     * @throws
     * @title 新增一个老师
     * @description
     * @author Alex
     */
    @Options(useGeneratedKeys = true, keyProperty = "teacherId")
    @Insert("insert into teacher(teacherName,sex,tel,email,pwd,cardId,role,type,institute) " +
            "values(#{teacherName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role},#{type},#{institute})")
    public int add(Teacher teacher);
}
